import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'spec_code' },
			{ label: '外送单位 ',	name: 'outsourcing_company' },
			{ label: '科室 ',		name: 'project_parent_id', 		type:'select', idStr:'uuid' },
			{ label: '岗位',			name: 'project_id', 			type:'select' },
			{ label: '外送类型 ',	name: 'outsourcing_type', 		type:'select', data:[{ name:'常规外包', value:'1' },{ name:'临时外包', value:'2' }] },
			{ label: '外送时间',		names: ['start_at','end_at'], 	type:'date-range' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.props.onRef?.(this)
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}

	// paging
	fetch = () => $fn.fetch.call(this,'specimen/getOutsourcingList')
	
	// 表单
	cols = [
		{ title: '外送单位', 	dataIndex: 'outsourcing_company', 		width:150 },
		{ title: '外送时间', 	dataIndex: 'outsourcing_created_at', 	...$fn.table.time },
		{ title: '外送类型', 	dataIndex: 'outsourcing_type', 			width:200 },
		{ title: '条码号', 		dataIndex: 'spec_code', 				...$fn.table.spec_code },
		{ title: '姓名', 		dataIndex: 'patient_name', 				...$fn.table.name },
		{ title: '性别', 		dataIndex: 'sex_name', 					...$fn.table.sex  },
		{ title: '年龄', 		dataIndex: 'age', 						...$fn.table.age },
		{ title: '单一项目', 	dataIndex: 'kind_name', 				width:150 },
		{ title: '实验科室', 	dataIndex: 'project_parent_name', 		width:150  },
		{ title: '岗位', 		dataIndex: 'project_name', 				width:150 },
	]
	
	// 操作按钮
	controls = () => [
		Controls.exports.call(this, 'specimen/getOutsourcingList')					// 导出
	]
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow(forms, 'project_parent_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow(forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			this.setState({ forms })
		})
	}
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this,{isInit:window.isInit}) }
			</>
		)
	}
}

export default Index